import 'package:flutter/material.dart';
import 'package:yyads_text/yyads_text.dart';

class Home extends StatefulWidget {
  const Home({ Key? key }) : super(key: key);

  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {
  bool getRewardAdStatus = false;
  bool getFullVideoStatus = false;
  String reward = "暂无状态";
  String fullvideo = "暂无状态";
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Column(
        children: [
          Container(
            height: 200,
            color: Colors.green,
            width: double.infinity,
            child: YyadsText.showBanner(bannerCallBack: BannerCallBack(

            )),
          ),
          TextButton(onPressed: ()async{
            showDialog(context: context, builder: (context){
              return AlertDialog(
                title: Text("正在获取广告"),
              );
            });
            getRewardAd();
          }, child: Text("得到激励视频广告"+getRewardAdStatus.toString()+reward)),
          TextButton(onPressed: ()async{
            showRewared();
          }, child: Text("flutter展示激励广告")),
           TextButton(onPressed: ()async{
            getFullVideoAd();
          }, child: Text("flutter得到全屏广告"+getFullVideoStatus.toString()+fullvideo)),
          TextButton(onPressed: ()async{
            showFullVideoAd();
          }, child: Text("flutter展示全屏广告"))
        ],
      ),
    );
  }
  void getRewardAd()async{
    var result = await YyadsText.getRewardVideoAd();
    if(result != null){
       setState(() {
      getRewardAdStatus = result;
    });
    }else{
      print("flutterJUFEI"+result.toString());
    }
   
    Navigator.pop(context);
    print("flutter得到激励视频广告"+result.toString());
  }
  void showRewared()async{
    var result = await YyadsText.showRewardVideoAd();
    if(result){
      setState(() {
        reward = "激励广告展示成功";
      });
    }
    print("flutter展示激励广告"+result.toString());
  }
  void getFullVideoAd()async{
    var result = await YyadsText.getFullVideoAd();
    setState(() {
      getRewardAdStatus = result;
    });
  }
  void showFullVideoAd()async{
    await YyadsText.showFullVideoAd();
  }
}